<?php
/**
 * Bom.php
 *
 * @copyright   2023 thingsworld.com.cn - All Rights Reserved
 * @link        http://thingsworld.com.cn/
 * @author      stiffer.chen <chenl@thingsworld.com.cn>
 * @created     2023-02-13 23:16:53
 * @modified    2023-02-13 23:16:53
 *
 */

namespace App\Models\Product;

use App\Models\BaseModel;
use Carbon\Carbon;

class Bom extends BaseModel
{
    protected $table = 'product_bom';

    protected $fillable = [
        'brand_id',
        'brand_name',
        'name',
        'specification',
        'model',
        'uom'
    ];

    protected $appends = [
        'create_time_format',
        'update_time_format',
    ];

    public function brand()
    {
        return $this->hasOne(Brand::class, 'id', 'brand_id');
    }

    public function getCreateTimeFormatAttribute()
    {
        return Carbon::parse($this->create_time)->toDateTimeString();
    }

    public function getUpdateTimeFormatAttribute()
    {
        return Carbon::parse($this->update_time)->toDateTimeString();
    }

    public function product_type_boms()
    {
        return $this->hasMany(\App\Models\Product\Type\Bom::class, 'product_bom_id');
    }
}